//
//  DialectCell.m
//  DialectShare
//
//  Created by timmy zhong on 3/20/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "DialectCell.h"
#import "CachedImage.h"
#import "User.h"

@implementation DialectCell
@synthesize view = _view, name = _name, address = _address, yuxi = _yuxi, date = _date, content = _content, avatar = _avatar, avatarContainer = _avatarContainer;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [[NSBundle mainBundle] loadNibNamed:@"DialectCell" owner:self options:nil];
        [self addSubview:self.view];
        _avatar = [[CachedImage alloc] initWithFrame:self.avatarContainer.bounds];
        [self.avatarContainer addSubview:_avatar];
    }
    return self;
}

- (void)dealloc
{
    self.view = nil;
    self.name = nil;
    self.address = nil;
    self.yuxi = nil;
    self.date = nil;
    self.content = nil;
    self.avatar = nil;
    self.avatarContainer = nil;
    [super dealloc];
}

- (void)showDialect:(Dialect *)dialect
{
    self.name.text = dialect.user.name;
    self.yuxi.text = dialect.yuxi;
    self.content.text = dialect.content;
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"MM/dd hh:mm"];
    NSDate *da = [NSDate dateWithTimeIntervalSince1970:dialect.dateline];
    
    self.date.text = [formatter stringFromDate:da];
    
    [formatter release];
    self.address.text = dialect.address;
    NSString *path = [[NSBundle mainBundle] pathForResource:@"user_icon" ofType:@"png"];
    [self.avatar showImageForUrl:dialect.user.avatar defaultImage:path];
}

@end
